/*
 * @Author: szx
 * @Date: 2022-03-12 14:02:07
 * @LastEditTime: 2022-03-12 14:24:44
 * @Description:
 * @FilePath: \leetcode\100-199\128\128.js
 */
/**
 * @param {number[]} nums
 * @return {number}
 */
var longestConsecutive = function (nums) {
    let res = 0;
    const set = new Set(nums);
    let cnt = 1;
    for (let i of set) {
        if (!set.has(i - 1)) {
            let j = i + 1;
            while (set.has(j++)) {
                cnt++;
            }
        }
        if (cnt > res) res = cnt;
        cnt = 1;
    }
    return res;
};
console.log(longestConsecutive([100, 4, 200, 1, 3, 2]));
console.log(longestConsecutive([0]));
console.log(longestConsecutive([]));
